package com.katze.boot.plugins.security.domain;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collection;
import java.util.Set;


public class UserDetail implements UserDetails, Serializable {

    @Serial
    private static final long serialVersionUID = -1L;

    private Long userId;

    private String username;

    private String firstname;

    private String password;

    private String status;

    private Set<Authority> authorities;

    private Set<String> permissions;


    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    @Override
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    @Override
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(Set<Authority> authorities) {
        this.authorities = authorities;
    }

    public Set<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(Set<String> permissions) {
        this.permissions = permissions;
    }

    public boolean isAccountNonExpired() {
        return status.equals("1");
    }

    public boolean isAccountNonLocked() {
        return !status.equals("0");
    }

    public boolean isCredentialsNonExpired() {
        return status.equals("1");
    }

    public boolean isEnabled() {
        return !status.equals("0");
    }
}
